package org.mparts.client.place;

import org.mparts.client.activity.AddressActivity;
import org.mparts.client.mvp.ActivityPlace;

import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
import com.google.inject.Inject;
import com.google.inject.Provider;

public class AddressPlace extends ActivityPlace<AddressActivity> {

	public static final String VIEW_HISTORY_TOKEN = "!address";

	@Inject
	public AddressPlace(AddressActivity activity) {
		super(activity);
	}

	@Prefix(value = VIEW_HISTORY_TOKEN)
	public static class Tokenizer implements PlaceTokenizer<AddressPlace> {

		private final Provider<AddressPlace> placeProvider;

		@Inject
		public Tokenizer(Provider<AddressPlace> placeProvider) {
			this.placeProvider = placeProvider;
		}

		@Override
		public AddressPlace getPlace(String token) {
			AddressPlace place = placeProvider.get();
			place.setPlaceName(token);
			return place;
		}

		@Override
		public String getToken(AddressPlace place) {
			return place.getPlaceName();
		}
	}

	@Override
	public String getHistoryToken() {
		return VIEW_HISTORY_TOKEN;
	}
}
